package com.loukou.lkt.web.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.loukou.lkt.lkt.bo.PageList;
import com.loukou.lkt.lkt.bo.PoPurchaseReturnOrderFinaceBo;
import com.loukou.lkt.lkt.bo.PoPurchaseReturnOrderFinaceListBo;
import com.loukou.lkt.lkt.enums.OrderOperateLogTypeEnum;
import com.loukou.lkt.lkt.req.PurchaseOrderReturnReqDto;
import com.loukou.lkt.lkt.resp.AuthInfo;
import com.loukou.lkt.lkt.resp.PageModel;
import com.loukou.lkt.lkt.resp.PoPurchaseOrderReturnDetailRespDto;
import com.loukou.lkt.lkt.resp.RespDto;
import com.loukou.lkt.lkt.service.OrderOperateLogService;
import com.loukou.lkt.lkt.service.PoPurchaseReturnOrderService;
import com.loukou.lkt.lkt.service.PurchaseReturnOrderService;

@Service
public class PoPurchaseReturnProcessor {
	@Autowired
	private PoPurchaseReturnOrderService poReturnService;
	@Autowired
	private OrderOperateLogService opLogService;
	@Autowired
	private PurchaseReturnOrderService returnOrderService;
	
	public PoPurchaseReturnOrderFinaceBo getReturnOrderByOrderId(int orderId){
		PoPurchaseReturnOrderFinaceBo bo=new PoPurchaseReturnOrderFinaceBo();
		bo=poReturnService.getFinaceCheckReturnOrder(orderId);
		return bo;
	}
	
	public RespDto<PageList<PoPurchaseReturnOrderFinaceListBo>> getFinaceCheckReturnOrderList(int orderState,
			String returnOrder, String supplierCode, String supplierName, int purchaseType, String returnPerson,
			Date startReturnTime, Date endReturnTime, int pageIndex, int pageSize){
		RespDto<PageList<PoPurchaseReturnOrderFinaceListBo>> resp=new RespDto<PageList<PoPurchaseReturnOrderFinaceListBo>>();
		resp=poReturnService.getFinaceCheckReturnOrderList(orderState, returnOrder, supplierCode, supplierName, purchaseType, returnPerson, startReturnTime, endReturnTime, pageIndex, pageSize);
		return resp;
	}
	
	@Transactional
	public RespDto<String> finaceAuditReturnOrder(int orderReturnId,AuthInfo user,String orderCode){
		RespDto<String> resp=new RespDto<String>();
		resp=poReturnService.finaceAuditReturnOrder(orderReturnId, user.getId());
		
		opLogService.saveOrderOperateLog(OrderOperateLogTypeEnum.TYPE_FINANCE_PASSED, orderCode, user.getId(), user.getUsername(), user.getRealName());
		
		returnOrderService.noticeWMS(orderReturnId);
		
		return resp;
	}
	
	@Transactional
	public RespDto<String> finaceRejectReturnOrder(int orderReturnId,AuthInfo user,String orderCode){
		RespDto<String> resp=new RespDto<String>();
		resp=poReturnService.finaceRejectReturnOrder(orderReturnId, user.getId());
		
		opLogService.saveOrderOperateLog(OrderOperateLogTypeEnum.TYPE_FINANCE_UNPASS, orderCode, user.getId(), user.getUsername(), user.getRealName());
		
		
		return resp;
	}
	
	/**
	 * 
	 * @param req
	 * @return 创建退货单
	 */
	public RespDto<String> submitReturnOrder(PurchaseOrderReturnReqDto req) {
		return poReturnService.submitReturnOrder(req);
	}
	
	/**
	 * 获取退货单详情（退货单编辑的订单获取复用）
	 * @param orderCode
	 * @return
	 */
	public PoPurchaseOrderReturnDetailRespDto getReturnOrderDetail(String orderCode) {
		return poReturnService.getReturnOrderDetail(orderCode);
	}
	
	/**
	 * 
	 * @param req
	 * @return 编辑退货单
	 */
	public RespDto<String> editReturnOrder(PurchaseOrderReturnReqDto req) {
		return poReturnService.editReturnOrder(req);
	}
	
	/**
	 * 
	 * @param warehouseId
	 * @param supplierId
	 * @param pageNum
	 * @param pageSize
	 * @return 退货起始页
	 */
	public PoPurchaseOrderReturnDetailRespDto getReturnOrderInit(
			int warehouseId,int supplierId) {
		return poReturnService.getReturnOrderInit(warehouseId, supplierId);
	}
	
}
